using System.ComponentModel.DataAnnotations;
using SqlSugar;

namespace TestWebApi.Models;

/// <summary>
/// UserModel 模型
/// </summary>
[SugarTable("User")]
public class UserModel
{
    public UserModel()
    {
    }

    // 默认构造函数
    public UserModel(string username, RoleEnum role, string email, string pwd, int age, string? sex)
    {
        UserName = username;
        Role = role;
        Email = email;
        Pwd = pwd;
        Age = age;
        Sex = sex;
    }

    // // 简化构造函数（仅必要参数）
    // public UserModel(string username, RoleEnum role, string email, string pwd)
    // {
    //     UserName = username;
    //     Role = role;
    //     Email = email;
    //     Pwd = pwd;
    // }

    // [SugarColumn(ColumnName = "id")] 可以在这里设置列名和数据库一致 此时可以不用构造函数
    [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
    public int Id { get; set; }

    [Required(ErrorMessage = "用户名是必填字段")]
    [StringLength(255, ErrorMessage = "用户名不能超过15个字符")]
    public string UserName { get; set; }

    [Required(ErrorMessage = "角色是必填字段")] public RoleEnum Role { get; set; }

    [Required(ErrorMessage = "邮箱是必填字段")]
    [EmailAddress(ErrorMessage = "邮箱格式不正确")]
    [StringLength(255, ErrorMessage = "邮箱不能超过50个字符")]
    public string Email { get; set; }

    [Required(ErrorMessage = "密码是必填字段")]
    [StringLength(255, MinimumLength = 8, ErrorMessage = "密码长度必须大于8个字符")]
    public string Pwd { get; set; }

    [Range(0, 130, ErrorMessage = "年龄必须在0到130之间")]
    public int? Age { get; set; }

    public string? Sex { get; set; }
}

public enum RoleEnum
{
    Admin = 0,
    User = 1
}